////////////////////////////////////////////////
// DESCRIPTION:
//     Support for accessing device driver
//     initialization data in the registry
//
// Legal Notices:
//     Copyright (c) 2008, Telliam Consulting, LLC.
//     All rights reserved.
//
//     Redistribution and use in source and binary forms, with or without modification,
//     are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//
//     * Redistributions in binary form must reproduce the above copyright notice,
//       this list of conditions and the following disclaimer in the documentation
//       and/or other materials provided with the distribution.
//
//     * Neither the name of Telliam Consulting nor the names of its contributors
//       may be used to endorse or promote products derived from this software
//       without specific prior written permission.
//
// Disclaimer:
//     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
//     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
//     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//     IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
//     INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
//     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
//     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//     LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
//     OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
//     OF THE POSSIBILITY OF SUCH DAMAGE.  
//
#pragma once

#include <devload.h>
#include <ddkreg.h>
#include <auto_xxx.hxx>

namespace FusionWare
{
    namespace DFX
    {
        ///////////////////////////////////////////////////////////////
        // Description:
        //   Class to manage reading standard device registry values
        //   for a device driver
        //
        // Remarks:
        //   Reads and stores standard device registry values
        //   these include:
        //
        // Note:
        //   The defaults are set in the constructor and not in ReadRegValues
        //   to allow clients to override some or all of the defaults without the
        //   need for deriving a new class just to handle different default
        //   considerations.
        //
        class DeviceRegValues : protected FusionWare::Win32::RegValues 
        {
        public:
            DeviceRegValues();
            virtual ~DeviceRegValues();

            // Read the values from the provided key and or subkey

            ///////////////////////////////////////////////////////
            // Description: 
            //    Read the device driver settings from the specified drivers "active"
            //    key.
            //
            // Input: 
            //    pRegPath             - Active path passed to the driver in xxx_Init
            //    numIrqs=0            - [Default: 0] Number of IRQs to expect
            //    pIrqSubKeyNames=NULL - [Default: NULL] subkey names for IRQ# 2 - IRQn
            // 
            //
            // Remarks: 
            //    This function loads the device driver's settings from the registry.
            //    pRegPath should be the path provided to the driver in the XXX_Init
            //    function. 
            //
            //    Some devices need more than one IRQ, This accounts for that by 
            //    using sub keys for additional IRQs while the first IRQ is listed
            //    like a normal one in the registry. For drivers that have only one IRQ
            //    pIRQSubKeyNames defaults to NULL. For those that need multiple IRQs
            //    pIRQSubKeyNames contains a list of the registry subkey names. The 
            //    first IRQ always comes from the root along with all of the other
            //    values, therefore the first entry in the subkeynames is for the
            //    second IRQ, the second entry for the third IRQ, etc...
            //
            bool ReadRegValues( const TCHAR* pRegPath, int NumIrqs=0, const TCHAR** pIrqSubKeyNames=NULL);

        public:
            BEGIN_REG_VALUE_TABLE(DeviceRegValues)
                REGVAL_DWORD(_T("Flags"), Flags)
            END_REG_VALUE_TABLE

            DeviceWindows Windows;
            ce::auto_array_ptr<IrqInfo> Irqs;
            DWORD Flags;
            ParentBusDriver ParentBus;

        protected:
            bool ReadIrqValues( FusionWare::Win32::RegKey& DevKey
                              , int NumIrqs 
                              , const TCHAR* pIrqSubKeyNames[]
                              );

        };
    }
}